package org.example.mytest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.mytest.entity.Myclass;
import org.example.mytest.entity.User;
import org.example.mytest.entity.Userone;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface UserMenyiMapper extends BaseMapper<Userone>
{
    @Select("select * from user")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),
            @Result(column = "class_id", property = "classId"),
            @Result(column = "enroll", property = "enroll"),
            @Result(column = "orders", property = "orders"),
            @Result(column = "email", property = "email"),

            @Result(column = "class_id", property = "myclass", javaType = Myclass.class,
                    one = @One(select = "org.example.mytest.mapper.MyclassMapper.findby"))
    })
    public List<Userone> getuserandclass();



    @Select("select * from user")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),
            @Result(column = "class_id", property = "classId"),
            @Result(column = "enroll", property = "enroll"),
            @Result(column = "orders", property = "orders"),
            @Result(column = "email", property = "email"),
            // 一对一关联映射
            //@Result(column = "class_id", property = "myclass", javaType = Myclass.class,
                   // one = @One(select = "org.example.mytest.mapper.MyclassMapper.findby"))
            @Result(column = "id", property = "score", javaType = List.class,
                    many= @Many(select = "org.example.mytest.mapper.ScoreMapper.findscoreby"))
    })
    public List<Userone> getuserandscore();
    @Select("select * from user")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),
            @Result(column = "class_id", property = "classId"),
            @Result(column = "enroll", property = "enroll"),
            @Result(column = "orders", property = "orders"),
            @Result(column = "email", property = "email"),
            // 一对一关联映射
            @Result(column = "class_id", property = "myclass", javaType = Myclass.class,
             one = @One(select = "org.example.mytest.mapper.MyclassMapper.findby")),
            @Result(column = "id", property = "score", javaType = List.class,
                    many= @Many(select = "org.example.mytest.mapper.ScoreMapper.findscoreby"))
    })
    public List<Userone> getuserandscoreandmyclass();
}

